package com.walker.component.page.resolve.query;

import java.util.LinkedHashMap;
import java.util.Map;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

/**
 * 对象查询器
 * 
 * @author 三丰
 * 
 */
public class ObjectQueryer implements Queryer {
	private final Map<String, Queryer> queryMap;// 存放json字段键值对

	public ObjectQueryer(Map<String, Queryer> queryMap) {
		this.queryMap = queryMap;
	}

	@SuppressWarnings("rawtypes")
	public Object query(Document document) {
		Map<Object, Object> result = new LinkedHashMap<Object, Object>();
		for (Map.Entry item : this.queryMap.entrySet()) {
			Object queryResult = ((Queryer) item.getValue()).query(document);
			result.put(item.getKey(), queryResult);
		}
		return result;
	}

	@SuppressWarnings("rawtypes")
	public Object query(Element element) {
		Map<Object, Object> result = new LinkedHashMap<Object, Object>();
		for (Map.Entry item : this.queryMap.entrySet()) {
			Object queryResult = ((Queryer) item.getValue()).query(element);
			result.put(item.getKey(), queryResult);
		}
		return result;
	}
}